﻿
@{
    ViewBag.Title = "CouponToUser";
}

@{
    ViewBag.Title = "用户列表";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<section class="content">
    <div class="row">
        <div class="col-md-12">
            <div class="box box-primary">
                <div class="box-header">
                    <form id="modal-search-form" class="form-inline">
                        <div class="form-group">
                            <label>电话</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="11" name="Mobile" autocomplete="off" />
                            <input type="hidden" value="@ViewBag.GroupID" id="CarGroupId" name="CarGroupId" />
                        </div>
                        <div class="form-group">
                            <label>姓名</label>
                            <input type="text" class="form-control" style="width:100px;" maxlength="50" name="UserName" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>卡级别</label>
                            <select id="CardLevel" name="CardLevel" class="form-control">
                                <option value="0">全部</option>
                            </select>
                        </div>
                        <div data-toggle="distpicker" class="form-group">
                            <label>所在地</label>
                            <select name="HProince" id="HProince" class="form-control"></select>
                            <select name="HCity" id="HCity" class="form-control"></select>
                        </div>
                        <div class="form-group">
                            <label>微信号</label>
                            <input type="text" class="form-control" style="width:100px;" name="WeChartNum" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <label>创建时间</label>
                            <input type="text" class="form-control" style="width:100px;" name="BCreateDate" id="BCreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" style="width:100px;" name="ECreateDate" id="ECreateDate" autocomplete="off" />
                        </div>
                        <div class="form-group">
                            <button type="button" class="btn btn-success btn-sm" id="modal-btnSearch">查找</button>
                        </div>

                        <h3 class="box-title"></h3>
                    </form>
                </div>
                <!-- /.box-header -->
                <div class="box-body table-responsive no-padding">
                    <table class="table table-bordered table-hover body-table-head">
                        <thead>
                            <tr>
                                <th>
                                    选择
                                </th>
                                <th>
                                    用户名称
                                </th>
                                <th>
                                    电话
                                </th>
                                <th>
                                    微信号
                                </th>
                                <th>
                                    卡号
                                </th>
                                <th>
                                    支付状态
                                </th>
                                <th>
                                    审核状态
                                </th>
                                <th>
                                    创建时间
                                </th>
                                <th class="t_c">
                                    操作
                                </th>
                            </tr>
                        </thead>
                        <tbody id="modal-tbodylist"></tbody>
                    </table>
                    <div class="no-data" id="modal-nodata" style="display:none;">
                        <div class="img-box"></div>
                        <div class="text">暂无数据</div>
                    </div>
                </div>
                <div class="box-footer clearfix ">
                    <ul id="modal-pagination" class="pagination pagination-sm no-margin pull-right"></ul>
                </div>
                <!-- /.box-body -->
                <button type="button" class="btn btn-success btn-sm" style="display: block; margin: 0 auto 15px auto;width: 160px;" id="btnCouponToUser">确定分配</button>
                <!-- /.box -->
            </div>
        </div>
    </div>




</section>
@section scriptsBottom{
    <script src="@Url.Content("~/lib/art-template/template-web.js")"></script>
    <script id="dataItemTpl" type="text/html">
        {{each rows}}
        <tr>
            <td>
                <input type="radio" data-userid="{{$value.UserID}}" class="chk radio" />
            </td>
            <td class="title">
                {{$value.UserName}}
            </td>
            <td class="title">
                {{$value.Mobile}}
            </td>
            <td class="title">
                {{$value.WeChartNum}}
            </td>
            <td>
                {{$value.CardCode}}
            </td>
            <td>
                {{$value.PayStateName}}
            </td>
            {{if $value.VehicleStatus==1}}
            <td>
                未审批
            </td>
            {{else if  $value.VehicleStatus==2}}
            <td>
                通过
            </td>
            {{else if $value.VehicleStatus==3}}
            <td>
                驳回
            </td>
            {{else}}
            <td></td>
            {{/if}}
            <td>
                {{$value.CreateDate}}
            </td>
            <td class="t_c">
                <button type="button" class="btn btn-info btn-xs" onclick="detail('{{$value.UserID}}')">详情</button>
            </td>
        </tr>
        {{/each}}
    </script>
    <script type="text/javascript">
        var modal_UserID = 0;
        window.selUserId = 0;

        $(document).ready(function () {
            $("#BCreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });
            $("#ECreateDate").datepicker({
                language: "zh-CN",
                autoclose: true,//选中之后自动隐藏日期选择框
                format: "yyyy-mm-dd"//日期格式，
            });

            $("#modal-btnSearch").click(function () {
                pageIndex = 1;
                list();
            });

            $("#btnCouponToUser").on("click", function () {
                toUserSave();
            })
            list();
        });
        function binds() {
            //radio单选效果
            $(".chk").on("click", function () {
                var $this = $(this);
                console.log($this);
                $(".chk").each(function () {
                    $(this).prop("checked", false);
                });
                $this.prop("checked", true);
                window.selUserId = $this.data("userid");
            });
        }
         //保存优惠券分配用户
        function toUserSave() {
            var selUserId = window.selUserId || 0;
            var selCouponId = "@ViewBag.CouponId";
            if (selUserId == 0) {
                BMCW.alert("请选择要分配的用户");
            } else {
                var url = '@Url.Action("RelaSave", "Coupon")' + "?userId=" + selUserId + "&couponId=" + selCouponId;
                 BMCW.ajax({
                        url: url,
                     type: "POST",
                        dataType: "json",
                            success: function (data) {
                                if (data.status == 0) {
                                    BMCW.alert(data.message);
                                    setTimeout(function () {
                                        window.location.reload();
                                    }, 2000);
                                } else {
                                    BMCW.alert(data.message);
                                }
                            }
                        });
            }
        };

        //页码
        var pageIndex = 1;
        //查询
        function list() {
            var fdata = $("#modal-search-form").serializeJson()
            var url = '@Url.Action("List", "User")' + "?page=" + pageIndex;
            //查询列表
            BMCW.ajax({
                url: url,
                type: 'POST',
                dataType: "json",
                data: fdata,
                success: function (dt) {
                    if (dt.total < 1) {
                        $("#modal-nodata").show();
                        document.getElementById('modal-tbodylist').innerHTML = "";
                        return;
                    }
                    $("#nodata").hide();
                    //模板渲染
                    var data = dt.rows;
                    var html = template('dataItemTpl', dt);
                    document.getElementById('modal-tbodylist').innerHTML = html;
                    binds();
                    //分页显示
                    $('#modal-pagination').twbsPagination("destroy");
                    $('#modal-pagination').twbsPagination({
                        totalItems: dt.total,
                        visiblePages: 10,
                        pageSize: 10,
                        startPage: parseInt(pageIndex),
                        onPageClick: function (event, page) {
                            pageIndex = page;
                            list();
                        }
                    });
                }
            });
        }

        //用户详情
        function detail(userid) {
            var url = '@Url.Action("Detail", "User")' + "?userId=" + userid;
            location.href = url;
        }



    </script>
}

